/**
 *
 */
package com.naiterui.ehp.bs.doctor.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.naiterui.ehp.bp.bo.recommend.MedicationRecomBO;
import com.naiterui.ehp.bp.bo.recommend.MedicationRecomDetailBO;
import com.naiterui.ehp.bp.utils.date.DateUtil;
import com.naiterui.ehp.bs.doctor.fegin.RecomFeginClient;
import com.naiterui.ehp.bs.doctor.service.IMedicationRecomSerivce;

/**
 * @Description 用药推荐
 */
@Service
public class AdMedicationRecomServiceImpl implements IMedicationRecomSerivce {

    private static final Logger LOGGER = LoggerFactory.getLogger(AdMedicationRecomServiceImpl.class);
    @Autowired
    private RecomFeginClient recomFeginClient;

    /**
     * 获取指定日期范围内的推荐记录
     * @param recomStatus 推荐购药状态
     * @param start 开始日期
     * @param end 结束日期
     * @return
     */
    @Override
    public List<MedicationRecomBO> getSpecifydayRecom(List<Integer> recomStatus, Date start, Date end) {
        String startStr = DateUtil.formatDate(start, DateUtil.DATE_TIME_FORMAT);
        String endStr = DateUtil.formatDate(end, DateUtil.DATE_TIME_FORMAT);
        String recomIdStr = recomStatus.stream().map(id -> id + "").collect(Collectors.joining(","));
        return this.recomFeginClient.getSpecifydayRecom(recomIdStr, startStr, endStr);
    }

    @Override
    public Map<Long, List<MedicationRecomDetailBO>> getRecomDetails(Set<Long> recomIdSet) {
        String recomIdStr = recomIdSet.stream().map(id -> id + "").collect(Collectors.joining(","));
        List<MedicationRecomDetailBO> detailBOList = this.recomFeginClient.getRecomDetails(recomIdStr);
        return detailBOList.stream().collect(Collectors.groupingBy(MedicationRecomDetailBO::getRecommendId));
    }

    @Override
    public Map<Long, Integer> getRecomStatusMap(Set<Long> recomIds) {
        return this.recomFeginClient.getRecomStatusMap(recomIds);
    }
}
